/*
 * KriteriaTop10.java
 *
 * Created on September 15, 2008, 11:48 AM
 */
package com.indragunawan.restobiz.app;

import java.awt.event.KeyEvent;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdesktop.application.Action;

/**
 *
 * @author  igoens
 */
public class KriteriaTop10 extends javax.swing.JDialog {

    private static final long serialVersionUID = 257063043495001140L;

    private int i;
    private GeneralConfig cfg = new GeneralConfig();
    private Date TAwal;
    private Date TAkhir;
    private boolean bukaLaporan;
    private String kelompok;

    /** Creates new form KriteriaTop10 */
    public KriteriaTop10(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        fillKelompokList();
        initTanggal();
    }

    private void fillKelompokList() {
        try {
            List kelompokList = cfg.getKelompokMenu();

            kelompokField.removeAllItems();
            for (i = 0; i <= kelompokList.size() - 1; i++) {
                kelompokField.addItem(String.valueOf(kelompokList.get(i)));
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            Logger.getLogger(GeneralConfig.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void setConfirmOpen(Boolean Confirm) {
        this.bukaLaporan = Confirm;
    }

    public Boolean getConfirmOpen() {
        return this.bukaLaporan;
    }

    private void setKriteriaKelompok() {
        kelompok = "";
        if (kelompokField.getSelectedIndex() != -1) {
            kelompok = String.valueOf(kelompokField.getSelectedItem());
        }
    }

    public String getKriteriaKelompok() {
        return this.kelompok;
    }

    private void setKriteriaPeriode() {
        TAwal = tanggalAwalField.getDate();
        TAkhir = tanggalAkhirField.getDate();
    }

    public Date getTanggalAwal() {
        return TAwal;
    }

    public Date getTanggalAkhir() {
        return TAkhir;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        kriteriaPanel = new javax.swing.JPanel();
        tanggalAwalLabel = new javax.swing.JLabel();
        tanggalAwalField = new org.jdesktop.swingx.JXDatePicker();
        tanggalAkhirLabel = new javax.swing.JLabel();
        tanggalAkhirField = new org.jdesktop.swingx.JXDatePicker();
        kelompokField = new javax.swing.JComboBox();
        kelompokLabel = new javax.swing.JLabel();
        batalButton = new javax.swing.JButton();
        okButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(com.indragunawan.restobiz.app.MainApp.class).getContext().getResourceMap(KriteriaTop10.class);
        setTitle(resourceMap.getString("laporanTop10.title")); // NOI18N
        setName("laporanTop10"); // NOI18N

        kriteriaPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("kriteriaPanel.border.title"))); // NOI18N
        kriteriaPanel.setName("kriteriaPanel"); // NOI18N

        tanggalAwalLabel.setDisplayedMnemonic('T');
        tanggalAwalLabel.setLabelFor(tanggalAwalField);
        tanggalAwalLabel.setText(resourceMap.getString("tanggalAwalLabel.text")); // NOI18N
        tanggalAwalLabel.setName("tanggalAwalLabel"); // NOI18N

        tanggalAwalField.setName("tanggalAwalField"); // NOI18N

        tanggalAkhirLabel.setDisplayedMnemonic('a');
        tanggalAkhirLabel.setLabelFor(tanggalAkhirField);
        tanggalAkhirLabel.setText(resourceMap.getString("tanggalAkhirLabel.text")); // NOI18N
        tanggalAkhirLabel.setName("tanggalAkhirLabel"); // NOI18N

        tanggalAkhirField.setName("tanggalAkhirField"); // NOI18N

        kelompokField.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "KELOMPOK" }));
        kelompokField.setBackground(resourceMap.getColor("kelompokField.background")); // NOI18N
        kelompokField.setName("kelompokField"); // NOI18N

        kelompokLabel.setDisplayedMnemonic('K');
        kelompokLabel.setLabelFor(kelompokField);
        kelompokLabel.setText(resourceMap.getString("kelompokLabel.text")); // NOI18N
        kelompokLabel.setName("kelompokLabel"); // NOI18N

        javax.swing.GroupLayout kriteriaPanelLayout = new javax.swing.GroupLayout(kriteriaPanel);
        kriteriaPanel.setLayout(kriteriaPanelLayout);
        kriteriaPanelLayout.setHorizontalGroup(
            kriteriaPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(kriteriaPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(kriteriaPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tanggalAkhirLabel)
                    .addComponent(tanggalAkhirField, javax.swing.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE)
                    .addComponent(tanggalAwalLabel)
                    .addComponent(kelompokLabel)
                    .addComponent(kelompokField, 0, 191, Short.MAX_VALUE)
                    .addComponent(tanggalAwalField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE))
                .addContainerGap())
        );
        kriteriaPanelLayout.setVerticalGroup(
            kriteriaPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(kriteriaPanelLayout.createSequentialGroup()
                .addComponent(tanggalAwalLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tanggalAwalField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tanggalAkhirLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tanggalAkhirField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(kelompokLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(kelompokField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(18, Short.MAX_VALUE))
        );

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(com.indragunawan.restobiz.app.MainApp.class).getContext().getActionMap(KriteriaTop10.class, this);
        batalButton.setAction(actionMap.get("closeKriteriaLaporan")); // NOI18N
        batalButton.setMnemonic('B');
        batalButton.setText(resourceMap.getString("batalButton.text")); // NOI18N
        batalButton.setName("batalButton"); // NOI18N
        batalButton.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                batalButtonKeyPressed(evt);
            }
        });

        okButton.setAction(actionMap.get("setKriteriaLaporan")); // NOI18N
        okButton.setMnemonic('O');
        okButton.setText(resourceMap.getString("okButton.text")); // NOI18N
        okButton.setName("okButton"); // NOI18N
        okButton.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                okButtonKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(kriteriaPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(159, Short.MAX_VALUE)
                .addComponent(okButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(batalButton)
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {batalButton, okButton});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(kriteriaPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(batalButton)
                    .addComponent(okButton))
                .addContainerGap(13, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void okButtonKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_okButtonKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        setKriteriaLaporan();
    }
}//GEN-LAST:event_okButtonKeyPressed

private void batalButtonKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_batalButtonKeyPressed
    closeKriteriaLaporan();
}//GEN-LAST:event_batalButtonKeyPressed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton batalButton;
    private javax.swing.JComboBox kelompokField;
    private javax.swing.JLabel kelompokLabel;
    private javax.swing.JPanel kriteriaPanel;
    private javax.swing.JButton okButton;
    private org.jdesktop.swingx.JXDatePicker tanggalAkhirField;
    private javax.swing.JLabel tanggalAkhirLabel;
    private org.jdesktop.swingx.JXDatePicker tanggalAwalField;
    private javax.swing.JLabel tanggalAwalLabel;
    // End of variables declaration//GEN-END:variables

    private void initTanggal() {
        Date today = new Date();
        tanggalAwalField.setDate(today);
        tanggalAkhirField.setDate(today);
    }

    @Action
    public void setKriteriaLaporan() {
        setKriteriaPeriode();
        setKriteriaKelompok();
        this.setConfirmOpen(true);
        this.dispose();
    }

    @Action
    public void closeKriteriaLaporan() {
        this.setConfirmOpen(false);
        this.dispose();
    }
}
